package com.sky.controller.user;


import com.github.pagehelper.Page;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {


    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> subit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){

       OrderSubmitVO orderSubmitVO= orderService.submitOrder(ordersSubmitDTO);
       return Result.success(orderSubmitVO);
    }

    @PutMapping("/payment")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO){

        orderService.payMent(ordersPaymentDTO);
        String estimatedDeliveryTime= String.valueOf(LocalDateTime.now().plusHours(1));
        return Result.success(estimatedDeliveryTime);
    }

    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(int page, int pageSize, Integer status){

        PageResult pageResult=orderService.pageQueryByUsers(page,pageSize,status);

        return Result.success(pageResult);
    }

    @GetMapping("/orderDetail/{id}")
    public  Result<OrderVO> getOrderDetailById(@PathVariable("id") long id){

        OrderVO orderVO=orderService.getOrderDetailById(id);


        return Result.success(orderVO);
    }

    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable("id") long id){

        orderService.userCancelById(id);
        return Result.success();
    }

    //再来一单
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable long id){
        orderService.repetition(id);
        return Result.success();

    }

    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable long id){
        orderService.reminder(id);
        return Result.success();
    }


}
